const jwt=require("jsonwebtoken")
const users=require("../database/users")

module.exports=(req,res)=>{
  const {token}=req.query

    jwt.verify(token, "千锋H5", async (err, data)=>{
      if(err){ 
        res.send({
          code:2,
          msg:"验证失败未登录",
          data:err.toString()
        })
        return
      }
      const userData=await users.find({userId:data.userId})
      if(userData.length<1){
        res.send({
          code:0,
          msg:"登录失效",
          data:null
        })
      }else{
        res.send({
          code:1,
          msg:"token验证成功",
          data:userData
        })
      }
  })
}